package com.amigo.online.provider.user.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.amigo.online.common.core.mybatis.MyMapper;
import com.amigo.online.provider.user.model.entity.UserDevice;
import org.springframework.stereotype.Repository;

@Repository
public interface RecordDeviceMapper extends MyMapper<UserDevice> {

    @Select("select id,unique_code,type,created_time,updated_time from user_device_tbl where user_id = #{userId} limit 1")
    UserDevice getByUserId(Long userId);

    @Select("select id,unique_code,type,created_time,updated_time from user_device_tbl "
            + " where user_id = #{userId} and unique_code = #{uniqueCode} limit 1")
    UserDevice getByUserIdAndUniqueCode(Long id, String uniqueCode);

    @Update("update user_device_tbl set unique_code = null,updated_time = #{updatedTime} where user_id = #{userId}")
    int clearUniqueCode(@Param("userId") Long userId, @Param("updatedTime") Long updatedTime);

}
